home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DllSys_Files / STEP / STEP.C
Encoding:
C/C++ Source or Header  |  2002-03-08  |  1.6 KB  |  45 lines

  1. // Dynamic link library implementation of NeuroSolutions Step component
  2.  
  3. #include "NSDLL.h"
  4.  
  5. /*****************************/
  6. /* Gradient search procedure */
  7.  
  8. __declspec(dllexport) void performStep(
  9.     DLLData    *instance,    // Pointer to instance data (may be NULL)
  10.     NSFloat    *weights,    // Pointer to the vector of weights
  11.     int    length,            // Length of the weight vector
  12.     NSFloat    *gradient,    // Pointer to the vector of gradients, one for each weight
  13.     NSFloat    *step,        // Pointer to the learning rate/s
  14.     BOOL    individual,    // Indicates whether there is one learning rate for all weights (FALSE),
  15.                         // or each weight has its own learning rate (TRUE)
  16.     int        stepDivisor,// The number each step size should be divided by
  17.     BOOL    decayWeights,    // TRUE if weight decay is active
  18.     NSFloat decayRate    // Rate to decay weights if weight decay is active
  19.     )
  20. {
  21.     register int i;
  22.  
  23.     for (i=0; i<length; i++)
  24.         weights[i] += (step[individual?i:0]/stepDivisor) * gradient[i] - (decayWeights ? weights[i] * decayRate : 0.0f);
  25. }
  26.  
  27. /******************************************/
  28. /* Management of instance data (OPTIONAL) */
  29. /*
  30. __declspec(dllexport) DLLData *allocStep(
  31.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  32.     int    length,        // Length of the weight vector
  33.     BOOL    individual    // Indicates whether their is one learning rate for all weights (FALSE),
  34.                 // or each weight has its own learning rate
  35.     )
  36. {
  37.     DLLData *instance = allocDLLInstance(oldInstance);
  38.     return instance;
  39. }
  40.  
  41. __declspec(dllexport) void freeStep(DLLData *instance)
  42. {
  43.     freeDLLInstance(instance);
  44. }
  45. */